package com.jifeng.br.pjj.bookreader.controller.admin;


import com.jifeng.br.pjj.bookreader.entity.AdEntity;
import com.jifeng.br.pjj.bookreader.service.AdService;
import com.jifeng.br.pjj.bookreader.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 广告表 前端控制器
 * </p>
 *
 * @author 机蜂
 * @since 2023-07-11
 */
@RestController
@RequestMapping("/ad")
public class AdController {
    @Autowired
    private AdService adService;

    @GetMapping("/page")
    public R page(int page, int limit, AdEntity adEntity) {
        return R.data(adService.getPage(page, limit, adEntity));
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable int id) {
        return R.data(adService.getById(id));
    }

    @PostMapping(value = {"/update", "/order"})
    public R update(@RequestBody AdEntity adEntity) {
        adService.saveOrUpdate(adEntity);
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable int id) {
        adService.removeById(id);
        return R.ok();
    }
}

